from fastapi import APIRouter, HTTPException

router = APIRouter(
    prefix="/items",  # 该路由下的所有路径前缀为 /items
    tags=["items"]    # OpenAPI 文档中的标签分类
)

fake_items_db = {"apple": "A fruit", "book": "Something to readok1"}

@router.get("/")
async def read_items():
    return fake_items_db

@router.get("/{item_id}")
async def read_item(item_id: str):
    if item_id not in fake_items_db:
        raise HTTPException(status_code=404, detail="Item not found")
    return {"name": item_id, "description": fake_items_db[item_id]}